//
//  JGNewMessageBtn.m
//  JGRider
//
//  Created by 单启志 on 2018/4/23.
//  Copyright © 2018年 ffq. All rights reserved.
//

#import "JGNewMessageBtn.h"
@interface JGNewMessageBtn()
@property(nonatomic,strong)UILabel *numLab;
@end
@implementation JGNewMessageBtn

-(instancetype)init{

    if (self=[super init]) {
        //self.count=0;

        [self setImage:[UIImage imageNamed:@"notice"] forState:UIControlStateNormal];

        self.frame=CGRectMake(0, 0, 48, 47);
    }
    return self;
}

-(void)setCount:(NSInteger)count{
    _count=count;
    NSString *imageName=@"notice";

    if (count>0) {
        //imageName=@"newnotice";
        [self addSubview:self.numLab];
    }
     [self setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];

}

-(UILabel *)numLab{
    if (_numLab==nil) {
        _numLab=[[UILabel alloc]initWithFrame:CGRectMake(self.width-22, 9, 14, 14)];
        _numLab.text=[NSString stringWithFormat:@"%ld",self.count];
        _numLab.textColor=HEXCOLOR(0xffffff);
        _numLab.font=[UIFont systemFontOfSize:9];
        //[_numLab sizeToFit];
        _numLab.textAlignment=NSTextAlignmentCenter;
       _numLab.backgroundColor=HEXCOLOR(0x5981f1);
        _numLab.layer.cornerRadius=7;
        _numLab.layer.masksToBounds=YES;
    }
    return _numLab;
}

@end
